package summary;

import java.io.*;

/**
 * @Author admin
 * @Date 2019/4/12 8:07
 * 字节缓冲流：图片，视频等
 * 一次去读写一个字节数组
 */
public class Test1 {
    public static void main(String[] args) {
        /*1.创建字节缓冲流对象
         * 2.循环操作哦：
         * 读取源文件一个字节数组，写入到目标文件
         * 3.刷新
         * 4.关闭*/
        InputStream in = null;
        BufferedInputStream bis = null;
        OutputStream out = null;
        BufferedOutputStream bos = null;
        try {
            in = new FileInputStream("a.jpeg");
            bis = new BufferedInputStream(in);
            out = new FileOutputStream("D:\\xuexiaoban.jpeg");
            bos = new BufferedOutputStream(out);

            byte[] bytes = new byte[1024];
            int len = 0;
            while ((len = bis.read(bytes)) != -1) {
                bos.write(bytes, 0, len);
            }
            bos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
